import request from '@/utils/request'

export function fileTreeSelect(baseId) {
  return request({
    url: '/knowledge/file/fileTree/' + baseId,
    method: 'get'
  })
}

// 查询知识库文档列表
export function listFile(query) {
  return request({
    url: '/knowledge/file/list',
    method: 'get',
    params: query
  })
}

// 查询知识库文档详细
// export function getFile(id) {
//   return request({
//     url: '/knowledge/file/' + id,
//     method: 'get'
//   })
// }

// 新增知识库文档(当前目录ID-fileId,当前目录名称-fileName,知识库ID-baseId)
export function addDir(data) {
  return request({
    url: '/knowledge/dir',
    method: 'post',
    data: data
  })
}

// 修改知识库文档(当前目录ID-fileId,当前目录名称-fileName)
export function updateDir(data) {
  return request({
    url: '/knowledge/dir',
    method: 'put',
    data: data
  })
}
// 删除知识库文档(当前目录ID-fileId)
export function delDir(id) {
  return request({
    url: '/knowledge/dir/' + id,
    method: 'delete'
  })
}

// 删除知识库文档
export function delFile(data) {
  // console.log('delFile',data)
  return request({
    url: '/knowledge/file/',
    method: 'delete',
    params: data
  })
}
// 获取文件预览地址
export function getFileUrl(data) {
  return request({
    url: 'knowledge/file/preview',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: data
  })
}
// 获取clientType
export function getClientType() {
  return request({
    url: 'homePage/config',
    method: 'get',
  })
}
// 获取文件预览地址
export function getFileUrlQa(data) {
  return request({
    url: 'knowledge/file/previewQa',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: data
  })
}
// doc类型文件，二进制数据流
// headers: {
//   'Content-Type': 'multipart/form-data'
// }
export function getDocFile(data) {
  return request({
    url: 'knowledge/file/download',
    method: 'post',
    responseType: 'arraybuffer', // 确保返回的是二进制数据
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    
    data: data
  })
}
// 同步文件
export function syncFile(data) {
  return request({
    url: '/knowledge/file/sync',
    method: 'post',
    data: data
  })
}

// 获取文件预览地址
export function getDocumentChunk(data) {
  return request({
    url: '/knowledge/file/getDocumentChunk',
    method: 'post',
    data: data
  })
}